<?php

namespace App\Http\Controllers\Admin;

use App\Models\Admin\Admins;
use http\Env\Response;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    /**
     * 管理员登陆
     * @param Request $request
     */
    public function index(Request $request)
    {
        if (empty($_POST)) return view('Admin/Public/login');
        $request->validate([
            'account' => 'required', 'regex:/^[a-zA-Z0-9\u4e00-\u9fa5]{3,12}$|max:12|min:1',
            'password' => 'required', 'regex:/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/'
        ]);
        $params = $_POST;
        $login = Admins::checkLogin($params);
        return response()->json($login);
    }

    /**
     * 退出登录
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function loginOut(Request $request)
    {
        Admins::loginOut();
        return redirect('myadmin/login');
    }

}